{include file="public/head"}
<div class="main">
    {include file="public/left"}
    <div class="middle">
    {include file="public/header"}
    <h3 class="task_tab">{:__('您的位置：首页>任务大厅')}</h3>
    <div class='task_list'>
        <ul class="task_class_index">
            <dl><i style="color: rgb(203,72,0);" class="fa fa-caret-right" aria-hidden="true"></i><a href="/index/Index/tasklist">{:__('所有分类')}</a></dl>
        </ul>
        <div class="all_task layui-tab">
            <ul class='layui-tab-title'>
                <li class="layui-this">{:__('所有任务')}</li>
            </ul>
            <ul class="task_select">
                <h5>{:__('任务筛选')}</h5>
                <p id="intergralzone"><span>{:__('赏金额度')}：</span><a data-target="" class="use_this">{:__('不限')}</a></p>
                <p id="mission_status"><span>{:__('任务进度')}：</span><a data-target="" class="use_this">{:__('不限')}</a></p>
                <p class="timezone"><span>{:__('发布时间')}：</span><a data-target="" class="use_this">{:__('不限')}</a></p>
            </ul>
            <ul class="task_list_index">
                <h6>
                    <button class="sort" data-target="mission_id">{:__('默认排序')}</button>
                    <button class="sort" data-target="money">{:__('任务赏金')}</button>
                    <button class="sort" data-target="expire">{:__('剩余时间')}</button>
                    <button class="sort" data-target="browse">{:__('浏览次数')}</button>
                    <input type="text" id="title" class="layui-input" value="{$title}" placeholder="{:__('请输入标题')}"/>
                    <button onclick="get_task(1)">{:__('搜索')}</button>
                </h6>
                <p class="task_list_title">
                    <span>{:__('任务赏金(金币)')}</span>
                    <span style="width: 20%;">{:__('任务标题')}</span>
                    <span>{:__('投标数量')}</span>
                    <span>{:__('任务顾主')}</span>
                    <span>{:__('任务分类')}</span>
                    <span>{:__('任务进度')}</span>
                    <span>{:__('剩余时间')}</span>
                </p>
                
            </ul>
            <div id="in_page"></div>
        </div>
    </div>
    {include file="public/foot"}
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<script>
    var cat_id = "{$id}";
    var cat_id_int = parseInt(cat_id);
    var sort = '{$sort}';
    if(sort==''){
        sort = 'mission_id';
    }
    var mission_no = '{$mission_no}';
    // 任务筛选
    function indata(){
        var mission_category = getLocalStorage('mission_category');
        var intergralzone = getLocalStorage('intergralzone');
        var mission_hall_status = getLocalStorage('mission_hall_status');
        var timezone = getLocalStorage('timezone');
        var htl = "";
        if(mission_category != null && mission_category != '' && mission_category != undefined &&
        intergralzone != null && intergralzone != '' && intergralzone != undefined && 
        mission_hall_status != null && mission_hall_status != '' && mission_hall_status != undefined && 
        timezone != null && timezone != '' && timezone != undefined){
            mission_categoryObj = JSON.parse(mission_category);
            for(i in mission_categoryObj){
                htl += '<dl data-target="'+mission_categoryObj[i]['id']+'"><i class="fa fa-caret-right" aria-hidden="true"></i><a href="/index/Index/tasklist?id='+mission_categoryObj[i]['id']+'">'+mission_categoryObj[i]['name']+'</a></dl>';
            }
            $(".task_class_index").append(htl);
            htl = "";
            intergralzoneObj = JSON.parse(intergralzone);
            for(i in intergralzoneObj){
                if("{$intergralzone}" == i){
                    $("#intergralzone a.use_this").removeClass("use_this");
                    htl += '<a data-target='+i+' class="use_this">'+intergralzoneObj[i]+'</a>';
                } else {
                    htl += '<a data-target='+i+'>'+intergralzoneObj[i]+'</a>';
                }
            }
            $("#intergralzone").append(htl);

            htl = "";
            mission_hall_statusObj = JSON.parse(mission_hall_status);
            for(i in mission_hall_statusObj){
                if("{$mission_hall_status}" == i){
                    $("#mission_status a.use_this").removeClass("use_this");
                    htl += '<a data-target='+i+' class="use_this">'+mission_hall_statusObj[i]+'</a>';
                } else {
                    htl += '<a data-target='+i+'>'+mission_hall_statusObj[i]+'</a>';
                }
            }
            $("#mission_status").append(htl);

            htl = "";
            timezoneObj = JSON.parse(timezone);
            for(i in timezoneObj){
                htl += '<a data-target='+i+'>'+timezoneObj[i]+'</a>';
            }
            $(".timezone").append(htl);
            return true;
        } else {
            return false;
        }
    }
    objs = {
        'mission_category':1,
        'mission_hall_status':1,
        'timezone':1,
        'intergralzone':1
    };
    var dataflag = indata();
    if(dataflag == false){
        CacheLoad(objs);
        $(document).queue("mission_category,mission_hall_status,timezone,intergralzone,",function(){
            indata();
        });
    }
    
    $(".task_select p a").click(function(){
        var _this = $(this);
        _this.addClass("use_this");
        _this.siblings("a").removeClass("use_this");
    });
    var total = 0;
    var afterpage = 1;
    var slt_bid_mode = '{$slt_bid_mode}';
    function get_task(nowpage){
        var intergralzone = $("#intergralzone .use_this").attr("data-target");
        var mission_status = $("#mission_status .use_this").attr("data-target");
        var timezone = $(".timezone .use_this").attr("data-target");
        var title = $("#title").val();
        // 任务列表
        $.ajax({
            url:'/api/mission/index',
            type:"get",
            data:{limit:20,page:nowpage,cat_id:cat_id,status:mission_status,intergralzone:intergralzone,timezone:timezone,sort:sort,title:title,slt_bid_mode:slt_bid_mode,mission_no:mission_no},
            success:function(ret){
                $(".task_list_page").remove();
                var htl = "";
                if(ret['code'] != 1 && ret['code'] != 401){
                    layer.msg(ret['msg'],{icon:2});
                } else if(ret['code'] == 1){
                    if(ret['data'] == '' && ret['data'] == null || ret['data'] == undefined){
                        return false;
                    }
                    if(ret['data']['ls'] == '' && ret['data']['ls'] == null || ret['data']['ls'] == undefined){
                        return false;
                    }
                    for(i in ret['data']['ls']){
                        var status = '';
                        if(ret['data']['ls'][i]['status'] == 1){
                            status = "{:__('待付款')}";
                        } else if(ret['data']['ls'][i]['status'] == 2){
                            status = "{:__('待审核')}";
                        } else if(ret['data']['ls'][i]['status'] == 3){
                            status = "{:__('进行中')}";
                        } else if(ret['data']['ls'][i]['status'] == 4){
                            status = "{:__('完成')}";
                        } else if(ret['data']['ls'][i]['status'] == 5){
                            status = "{:__('仲裁中')}";
                        }
                        if(ret['data']['ls'][i]['left_time'] == 0){
                            ret['data']['ls'][i]['left_time'] = "{:__('0分钟')}";
                        }
                        if(ret['data']['ls'][i]['title'] == null || ret['data']['ls'][i]['title'] == undefined){
                            ret['data']['ls'][i]['title'] = "{:__('暂无标题')}";
                        }
                        slt_bid_mode_type = '';
                        if(ret['data']['ls'][i]['money_cfg']['slt_bid_mode'] == 1){
                            slt_bid_mode_type = '{:__("普通")}';
                        } else if(ret['data']['ls'][i]['money_cfg']['slt_bid_mode'] == 2){
                            slt_bid_mode_type = '{:__("等级")}';
                        } else if(ret['data']['ls'][i]['money_cfg']['slt_bid_mode'] == 3){
                            slt_bid_mode_type = '{:__("计件")}';
                        }
                        if(ret['data']['ls'][i]['user_info'] == null || ret['data']['ls'][i]['user_info'] == undefined ||
                         ret['data']['ls'][i]['user_info'] == '' ||
                         ret['data']['ls'][i]['user_info']['phone'] == null || ret['data']['ls'][i]['user_info']['phone'] == undefined){
                            ret['data']['ls'][i]['user_info']['phone'] = '';
                        }
                        if(ret['data']['ls'][i]['profile'] == null || ret['data']['ls'][i]['profile'] == undefined || ret['data']['ls'][i]['profile']['truename'] == '' || ret['data']['ls'][i]['profile']['truename'] == null || ret['data']['ls'][i]['profile']['truename'] == undefined){
                            username = ret['data']['ls'][i]['user_info']['username'];
                        } else {
                            username = ret['data']['ls'][i]['profile']['truename'];
                        }
                        htl += '<p class="task_list_page">'+
                            '<span class="task_money">$'+ret['data']['ls'][i]['money']+'</span>'+
                            '<span style="width: 20%;"><a href="/'+ret['data']['ls'][i]['route']+'">'+ret['data']['ls'][i]['title']+'</a></span>'+
                            '<span>'+ret['data']['ls'][i]['sign_limit']+'</span>'+
                            '<span>'+username+'</span>'+
                            "<span>"+slt_bid_mode_type+"</span>"+
                            '<span>'+status+'</span>'+
                            '<span class="task_time">'+ret['data']['ls'][i]['left_time']+'</span>'+
                            '</p>';
                    }
                    $(".task_list_title").after(htl);
                    total = ret['data']['total'];
                    if(nowpage == 1){
                        getpage();
                    }
                    $(document).dequeue('getask');
                }
            }
        });
    }
    $(document).queue('getask',function(){
        get_task(1);
    });
    function getpage()
    {
        //分页
        createpage('in_page',total,20,function(obj,first){
            var nowpage = obj.curr;
            if(nowpage != afterpage){
                get_task(nowpage);
            }
            afterpage = nowpage;
        });
    }
    $(document).queue('getask',function(){
        getpage();
    });
    $(document).dequeue('getask');
    $(document).on('click',"#intergralzone a,#mission_status a,.timezone a",function(){
        get_task(1);
    });
    $(".sort").click(function(){
        sort = $(this).attr('data-target');
        get_task(1);
    });
    if(cat_id_int > 0){
        $(".task_class_index dl[data-target="+cat_id_int+"]").css("background","rgb(219 218 218)");
    }
</script>